package com.health.healthproject.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@TableName("announcement")
public class Announcement {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String title;

    private String content;

    private String attachments;

    private Integer status;

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    private Long createBy;

    private Long updateBy;

    @TableLogic
    private Boolean deleted;

    // 公告状态枚举
    public static final class Status {
        public static final int DRAFT = 0;      // 草稿
        public static final int PUBLISHED = 1;   // 已发布
        public static final int RECALLED = 2;    // 已撤回
    }

    // 获取附件列表
    public List<String> getAttachmentList() {
        return attachments == null ? Collections.emptyList() :
                Arrays.stream(attachments.split(";"))
                        .filter(s -> !s.isEmpty())
                        .collect(Collectors.toList());
    }

    // 设置附件列表
    public void setAttachmentList(List<String> attachmentList) {
        this.attachments = attachmentList == null ? null :
                String.join(";", attachmentList);
    }
}